﻿/** NODE CLASS
 * Author: Preeti Francis
 * User ID : pxfranci@scotty.cs.wichita.edu
 * WSU ID: S578F746
 * Course: CS771 
 * Sem: S2014
 * 
 * Description of Class : The Node is class is the fundamental data structure for nodes in the A* algorithm. 
 * It consists of the state of the node, parent of the node, the action on the parent that resulted in the node, total cost (evaluation function),
 * Path cost (g(n)) and the Hash code of the state. The node class is used throughout the program and contains the entire tree structure from its 
 * ancestors.
 * **/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
 

namespace _8PiecePuzzle.DataStructures
{
    public class Node
    {
        //State of the node
        public int[][] State { get; set; }

        //Parent of the node (recursive tree structure)
        public Node Parent { get; set; }

        //Action on the parent that resulted in this node
        public _8PiecePuzzle.Enum.Action Action { get; set; }

        //Path Cost from root g(n)
        public int PathCost { get; set; }

        //Evaluation function cost from goal f(n) = g(n) + h(n)
        public int TotalCost { get; set; }

        //Hash code for the state of the node (used in visited nodes hash table and optimizing comparisons)
        public string StateHash 
        {
            get
            {
                StringBuilder sb = new StringBuilder();
                int n = State.Length;
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < n; j++)
                    {
                        sb.AppendFormat("{0}", State[i][j].ToString());
                                                
                    }
                }
                return sb.ToString();
            }
        }
        //public string StateHash { get { return string.Join("", State.Select(x => x.ToString()).ToArray()); } } //string.Join("", State.SelectMany(row => row)); }   }
    }
}
